package com.showtao.front.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.showtao.common.security.domain.Role;
import com.showtao.common.security.domain.User;
import com.showtao.common.security.enumeration.EUserStatus;

@SuppressWarnings("serial")
public class UserDto implements Serializable {

    private String userName;
    private EUserStatus status;
    private int loginFailureCount;
    private Date createdAt;
    private Date updatedAt;
    private List<String> roles;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public EUserStatus getStatus() {
        return status;
    }

    public void setStatus(EUserStatus status) {
        this.status = status;
    }

    public int getLoginFailureCount() {
        return loginFailureCount;
    }

    public void setLoginFailureCount(int loginFailureCount) {
        this.loginFailureCount = loginFailureCount;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }

    public static UserDto from(User user){
        UserDto dto = new UserDto();
        dto.setUserName(user.getUserName());
        dto.setStatus(user.getStatus());
        dto.setLoginFailureCount(user.getLoginFailureCount());
        dto.setCreatedAt(user.getCreatedAt());
        dto.setUpdatedAt(user.getUpdatedAt());
        if(user.getRoles()!=null){
            dto.setRoles(new ArrayList<String>());
            for(Role role : user.getRoles()){
                dto.getRoles().add(role.getRoleName());
            }
        }
        return dto;
    }
}
